﻿using ETA.Entity;
using ETA.IRepository;
using NHibernate;
using NHibernate.Criterion;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ETA.Repositories
{
    public class ReferrerLogRepository : NhRepositoryBase<ReferrerLog, string>, IReferrerLogRepository
    {
        public IList<ReferrerLog> QueryReferrerLogSumList(string userId, string userName, DateTime? sDate, DateTime? eDate)
        {
            ISession session = NHibernateHelper.GetSession();
            ICriteria crt = session.CreateCriteria(typeof(ReferrerLog));

            if (!string.IsNullOrEmpty(userId))
            {
                crt.Add(Restrictions.Like("UserId", "%" + userId + "%"));
            }

            if (!string.IsNullOrEmpty(userName))
            {
                crt.Add(Restrictions.Like("UserName", "%" + userName + "%"));
            }

            if (sDate != null)
            {
                crt.Add(Restrictions.Ge("CreateDate", sDate));
            }

            if (eDate != null)
            {
                crt.Add(Restrictions.Le("CreateDate", eDate));
            }

            var list = crt.List<ReferrerLog>();
            return list;
        }
    }
}
